import os.path
import pandas as pd
import datetime as datetime

# x = '50%'
#
# x1=相识度值.replace('%','')
# if(int(x1)<100):
#     相似度=True
# else:
#     相似度=False
#
# print(相似度)


# str='202.5×120×53.5MM'
# 规格=str.replace("MM",'').replace('mm','')
# 长宽厚=规格.split('×')
# print(长宽厚)

# globalConfig['Excel文件路径']=''
# 结果列表=['1','1234','10','2','错误']
# def insertResult(结果列表):
#     Excel文件 = Excel.Cs_OpenV3(self, globalConfig['Excel文件路径'], 1, "默认", 0, 1, "", "", 0, 0, var_ret=0,
#                                 skip_err=0, delay_before=0, delay_after=0)
#     Excel.Cs_WriteContent(self, Excel文件, "结果列表",
#                           {"column": "D", "lastColumn": "B", "lastRow": 1, "option": 0, "range": "A1:B1",
#                            "row": 结果列表[0], "startColumn": "A", "startRow": 1, "type": 0}, 结果列表[3], 1,
#                           skip_err=0, delay_before=0, delay_after=0)
#     Excel.Cs_Close(self, Excel文件, 1, 0, skip_err=0, delay_before=0, delay_after=0)
str1 = '提交成功！单号：M2023113000004'
print(str1.index('：'))
print(str1[str1.index('：') + 1:])


def insertResult(结果列表):
    str1 = str(结果列表[4])
    number = str1[str1.index('：') + 1:-1]
    Excel文件 = Excel.Cs_OpenV3(self, globalConfig['Excel文件路径'], 1, "默认", 0, 1, "", "", 0, 0, var_ret=0,
                                skip_err=0, delay_before=0, delay_after=0)
    Excel.Cs_WriteContent(self, Excel文件, "修改数据",
                          {"column": "D", "lastColumn": "B", "lastRow": 1, "option": 0, "range": "A1:B1",
                           "row": 结果列表[0] + 1, "startColumn": "A", "startRow": 1, "type": 0}, '成功', 1,
                          skip_err=0, delay_before=0, delay_after=0)
    Excel.Cs_WriteContent(self, Excel文件, "修改数据",
                          {"column": "E", "lastColumn": "B", "lastRow": 1, "option": 0, "range": "A1:B1",
                           "row": 结果列表[0] + 1, "startColumn": "A", "startRow": 1, "type": 0}, number, 1,
                          skip_err=0, delay_before=0, delay_after=0)
    Excel.Cs_Close(self, Excel文件, 1, 0, skip_err=0, delay_before=0, delay_after=0)


列表项 = [610005324.0, '202.5×120×53.5MM', 81.0, '提交成功！单号：M2023113000039', '', '']
print(type(列表项[0]))
if type(列表项[0]) == float:
    列表项[0] = str(int(列表项[0]))
if type(列表项[2]) == float:
    列表项[2] = str(int(列表项[2]))
print(列表项)

d2 = '快递申请模板.xlsx'
d1 = 'D:\Program Files (x86)\流程文件\快递申请流程\运行文件\快递申请模板.xlsx'
print(os.path.join(d1, d2))
print(os.path.basename(d1).split('.')[1])


行号 = 1
快递申请集合 = ['周文训', 'H123', '项目工程部', '13822448765', '文件', '1', '0.1', '1', '工作需要', '裕同',
                '宝安区裕同', '刘XX', '13487652975', '', 'SF20231023001', '']

读取结果 = pd.DataFrame({
    "name": ["小明", "小红", "小孙", "王小", "关宇", "刘蓓", "张菲"],
    "age": [20, 18, 27, 20, 28, 18, 25],
    "sex": ["男", "女", "男", "男", "男", "女", "女"],
    "收货地址": [669, 570, 642, 590, 601, 619, 701],
    "运行结果": ["北京", "深圳", "广州", "武汉", "深圳", "广州", "长沙"]
})
# strr=pd.read_excel("D:\Downloads\快递申请模板.xlsx")
for i in range(0, 6):
    if (('成功' in 读取结果['运行结果']) or ('失败' in 读取结果['运行结果'])):
        print('结果为空')

ss = {"申请人": 1, "工号": 2, "申请部门": 3, "寄件人联系电话": 4, "货物名称": 5, "数": 6, "重量": 7, "件数": 8,
      "发件是由": 9, "收件公司": 10,
      "收件地址": 11, "收件人姓名": 12, "收件人联系电话": 13, "申请收件时间": 14, "顺丰单号": 15, "运行结果": 16}

time='2023-12-07 04:20:33'

import pandas as pd

datetime = pd.to_datetime(time)
date = datetime.date()
year = datetime.year
month = datetime.month
day = datetime.day
hour = datetime.hour
if(hour<10):
    hour='0'+str(hour)
minute = datetime.minute
print(date,year,month,day,hour,minute)


# len='202.5×120×53.5MM'
len='202.5X120×53.5MM'
长宽厚=len.replace("MM",'').replace('mm','').replace('*','×').replace('X','×').replace('x','×').split('×')
print(长宽厚)

#OA申请时异常信息写入excel
[1, '周文训', 'cy20023', '项目工程部', '13822448765', '文件', '1', '0.1', '1', '工作需要', '裕同', '宝安区裕同', '刘XX', '13487652975', '', 'SF20231023001', '']
def insertResult(快递申请列表项):
    Excel文件 = Excel.Cs_OpenV3(self, 运行文件路径, 1, "默认", 0, 1, "", "", 0, 0, var_ret=0,
                                skip_err=0, delay_before=0, delay_after=0)
    Excel.Cs_WriteContent(self, Excel文件, "快递申请",
                          {"column": "D", "lastColumn": "B", "lastRow": 1, "option": 0, "range": "A1:B1",
                           "row": 快递申请列表项[0]+1, "startColumn": "A", "startRow": 1, "type": 0}, 快递申请列表项[表头字典['运行结果']], 1,
                          skip_err=0, delay_before=0, delay_after=0)
    Excel.Cs_Close(self, Excel文件, 1, 0, skip_err=0, delay_before=0, delay_after=0)

strr=''
if (strr != ''):
    print('bu')
print('kong')


def insertResultSF(快递申请列表项):
    Log.Info(self, '写入excel文件中{}'.format(快递申请列表项))
    Excel文件 = Excel.Cs_OpenV3(self, 运行文件路径, 1, "默认", 0, 1, "", "", 0, 0, var_ret=0,
                                skip_err=0, delay_before=0, delay_after=0)
    if (快递申请列表项[表头字典['顺丰单号']] != ''):
        Excel.Cs_WriteContent(self, Excel文件, "快递申请",
                              {"column": 表头字典['顺丰单号'], "lastColumn": "B", "lastRow": 1, "option": 0,
                               "range": "A1:B1",
                               "row": 快递申请列表项[0] + 1, "startColumn": "A", "startRow": 1, "type": 0},
                              快递申请列表项[表头字典['顺丰单号']], 1,
                              skip_err=0, delay_before=0, delay_after=0)
    Excel.Cs_WriteContent(self, Excel文件, "快递申请",
                          {"column": 表头字典['顺丰运行结果'], "lastColumn": "B", "lastRow": 1, "option": 0, "range": "A1:B1",
                           "row": 快递申请列表项[0]+1, "startColumn": "A", "startRow": 1, "type": 0}, 快递申请列表项[表头字典['顺丰运行结果']], 1,
                          skip_err=0, delay_before=0, delay_after=0)
    Excel.Cs_Close(self, Excel文件, 1, 0, skip_err=0, delay_before=0, delay_after=0)



转换时间结果='2023-12-06 12:30'
转换时间结果=str(转换时间结果).replace('-','').replace(' ','').replace(':','')
print(转换时间结果)

file_name = "D:\example.txt"
dirname=os.path.dirname(file_name)
basename=os.path.basename(file_name)
print(str(basename).split('.'))
print(dirname)
file_extension = file_name.split(".")[-1]
print(file_extension)

# filename=str(os.path.basename(运行结果文件))
# filename.split('.')[0]+转换时间结果+'.'+filename.split('.')[1]

import uuid

uid = uuid.uuid4()
uuid=str(uid).replace('-','')


# 单号='顺丰运单号：SF1378662309979 复制'
# str(元素文本值).replace('顺丰运单号：', '').replace(' 复制', '')

lie={'1021':[]}
lie['1021'].append('1234')
print('1021' in lie)


#利用这个解决，两个列表匹配相同项的方法
# 问题情景：给StudentScore表里的同学添加class信息，class信息在StudentInfo中
# 注意1: 4班的小D是国际生，但是StudentInfo没有他的信息，虽然他参与了考试，但是我们不希望在结果中包含他的成绩
# 注意2：1班的小E，StudentInfo有他的信息，但是因为他没有参加考试，所以结果中也不应该包含他的成绩
# 最后应该保留A B C这3位同学在math和art上的成绩，以及3位同学的班级
import numpy as np
import pandas as pd

StudentScore = pd.DataFrame([[1,"A","math",99],[1,"A","art",60],[2,"B","math",99],[2,"B","art",88],[3,"C","math",91],[3,"C","art",0],[4,"D","math",100],[4,"D","art",100]],columns=['StuID','StuName','subject','score'])
StudentInfo = pd.DataFrame([[1,"A","1-1"],[1,"E","1-1"],[2,"B","1-2"],[3,"C","1-2"]],columns=['StuID','StuName','class'])
print(StudentScore)
print(StudentInfo)
features = ['StuID','StuName']
ans = pd.merge(StudentScore,StudentInfo,how="inner",on=features)
print("---after merge---")
print(ans)
print("可以看到，没有E同学和D同学的任何信息")
